package com.java2104.service;

import com.java2104.entity.Job;
import com.java2104.mapper.JobMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class JobService {
    @Autowired
    private JobMapper jobMapper;
    public List<Job> selectJobName(String name){
        return jobMapper.selectJobName(name);

    }
    public Job get(Integer id){
        return jobMapper.findByPrimaryKey(id);
    }
    public int delete(Integer id){
        return jobMapper.delete(id);
    }
    public Map update(Job job){
        Map map=new HashMap();
        if (jobMapper.update(job)>0){
            map.put("remark","success");
            map.put("msg","修改成功");
        }else {
            map.put("remark","fail");
            map.put("msg","修改失败");
        }
        return map;
    }
    public Map insertJob(Job job){
        Map map=new HashMap();
        if (jobMapper.selectName(job.getName())==0){
            jobMapper.insertJob(job);
            map.put("name","success");
            map.put("msg","添加成功");
        }else {
            map.put("name","fail");
            map.put("msg","添加失败,名字重复");
        }

        return map;
    }
    public List<Integer> getIds(){
        return jobMapper.findIds();
    }

    public Integer getCountOfJobId(Integer id){
        return jobMapper.findCountOfJobId(id);
    }
}
